package com.mapbased.cc;

import com.mapbased.wfw.handler.*;
import com.mapbased.wfw.RenderContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mapbased.wfw.ExitException;

/**
 * <p>Title: </p>
 *
 * <p>Description:另一个版本的CacheHelper ，与CacheHelper的主要不同:
 * 在检查数据是否改变时,顺便把需要的数据从数据库中取出来,从而减少一次数据库访问.
 * 如果没有改变,从数据库取出空.
 *  </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 *
 */
public class PullCacheHelper
    extends CacheHelper
{
    public static interface IfModifiedGetter
    {
        long getIfModified(RenderContext rc,long from);

    }

    IfModifiedGetter img;

    public void setIfModifiedGetter(IfModifiedGetter img)
    {
        this.img=img;
    }

    final public long getLastModified(RenderContext rc)
    {
        throw new java.lang.IllegalAccessError(
            "Method has deprecated in PullCacheHelper");
        //return -1;
    }

    /**
     * the returned feature shuld put into request map
     * @param rc RenderContext
     * @param from long
     * @return long:the modify time
     */
    public long getIfModified(RenderContext rc,long from)
    {
        return this.img.getIfModified(rc,from);
    }

    public long filterRequest(RenderContext ctx)
    {
        if(this.isRedirectLocale())
        {
            throwIfNeedRedirect(ctx);
        }

        HttpServletRequest req=ctx.getRequest();
        long l=req.getDateHeader(this.__IfModifiedSince);
        return this.getIfModified(ctx,l);

    }
}
